package com.lgCore.client;

import com.lgCore.common.ProtocolCore;
import com.lgCore.factory.RpcServiceZkFactory;

/**
 * Rpc Tcp 客户端总入口
 */
public class SxRpcTcpClient implements RpcClient {
    /**
     * zk地址
     */
    private String zkServiceAddress;
    /**
     * zksession过期时间 毫秒
     */
    private int sessionTimeOut;
    /**
     * rpc区域
     */
    private String rpcSystemRegion;

    public SxRpcTcpClient(String zkServiceAddress, int sessionTimeOut,String rpcSystemRegion) {
        this.zkServiceAddress = zkServiceAddress;
        this.sessionTimeOut = sessionTimeOut;
        this.rpcSystemRegion = rpcSystemRegion;
    }
    public SxRpcTcpClient(String zkServiceAddress, int sessionTimeOut) {
        this.zkServiceAddress = zkServiceAddress;
        this.sessionTimeOut = sessionTimeOut;
    }

    @Override
    public void stop() throws Exception {
//        RpcServiceZkFactory.getZookServiceClient().close();
    }
    @Override
    public void start() throws Exception {
//        //启动连接zk
//        RpcServiceZkFactory.getZookServiceClient().connectZookeeper(zkServiceAddress, sessionTimeOut);
//        //初始化节点
//        RpcServiceZkFactory.getZookServiceClient().initServer();
//        //监控节点信息
//        RpcServiceZkFactory.getZookServiceClient().monitorZkNode();
//        //编码解码 kyro方式
//        ProtocolCore.kyroClass();

        //打开zk客户端
        RpcServiceZkFactory.openConnection(zkServiceAddress,rpcSystemRegion,null);

        //初始化配置
        RpcServiceZkFactory.getZookServiceClient().initConfig(RpcServiceZkFactory.getZkRootPath(),RpcServiceZkFactory.getClient());

        //初始化节点
        RpcServiceZkFactory.getZookServiceClient().initServer();
        //监控节点信息
        RpcServiceZkFactory.getZookServiceClient().monitorZkNode();
        //编码解码 kyro方式
        ProtocolCore.kyroClass();
    }


}
